{extend name="property/public/insidePageBase" /}
{block name="title"}新建报销申请{/block}
{block name="css"}
{__block__}
<style>
    body{ margin:0; }
    .layui-iconpicker-body.layui-iconpicker-body-page .hide {display: none;}
    body .layui-iconpicker .layui-iconpicker-icon-item{ width: 20.1%; }
    body{  background-color: #ffffff; }
    .layui-upload-img-box { float:left;  margin-bottom: 2px;margin-right: 2px; background: #e0e0e0;  padding: 1px; }
    .layui-upload-img {width: 82px; height: 82px; margin-bottom: 1px;}
</style>
{/block}
{block name="body"}
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane">
            <div class="layui-row">
                <div class="layui-col-xs6">
                    <div class="layui-form-item">
                        <label class="layui-form-label">费用金额</label>
                        <div class="layui-input-block">
                            <input type="text" name="amount" value="{$info['amount']??''}" autocomplete="off" class="layui-input" placeholder="费用总金额">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-form-item">
                        <label class="layui-form-label indispensable">发生时间</label>
                        <div class="layui-input-block">
                            <input type="text" name="use_time" value="{$info['use_time']??''}" readonly autocomplete="off" class="layui-input day-time" placeholder="yyyy-MM-dd">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">附件说明</label>
                <div class="layui-input-block" id="image_info">
                    <button type="button" class="layui-btn" id="upload_imgs" lay-data="{field: 'picture',data:{dir:'room/picture', field:'picture'}}">上传图片附件</button>
                    <div class="layui-upload-list" id="img_show">
                        {foreach $info['picture'] as $k=>$v}
                        <div class="layui-upload-img-box" id="{:md5($v)}-{$k}">
                            <img src="{$v}" class="layui-upload-img checkPictureByImg">
                            <input type="hidden" name="picture[]" value="{$v ??''}">
                            <p>
                                <a class="layui-btn layui-btn-xs cftoggleUpload" style="float: left" lay-data="{field: 'picture',data:{dir:'room/picture', field:'picture', room_picture_upload_index: '{:md5($v)}-{$k}'}}">修改</a>
                                <a class="layui-btn layui-btn-xs layui-btn-danger" onclick="this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);" style="float: right">删除</a>
                            </p>
                        </div>
                        {/foreach}
                        <div style="clear: both"></div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">费用说明</label>
                <div class="layui-input-block">
                    <textarea placeholder="请输入费用说明" class="layui-textarea" name="remark">{$info['remark']??''}</textarea>
                </div>
            </div>
            <div class="layui-form-item layui-hide">
                <button type="button" class="layui-btn layui-btn-primary replaceUploadImg toggleUpload" lay-data="{}"></button>
                <input type="hidden"  name="id" value="{$info['id']??''}" >
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="setting">确认保存</button>
                </div>
            </div>
        </form>
    </div>
</div>
{/block}
{block name="js"}
{__block__}
<script>
    layui.use(['form','layer','laydate'], function () {
        var form = layui.form, layer = layui.layer, $ = layui.$,laydate = layui.laydate;
        $('#upload_imgs').selectImages({
            confirm:function(res,elem) {
                for(var i in res) {
                    index = (new Date()).getTime()+''+i;
                    $('#img_show').append('<div class="layui-upload-img-box" id="'+index+'">' +
                        '<img src="' + res[i].src + '" class="layui-upload-img checkPictureByImg">' +
                        '<input type="hidden" name="picture[]" value="' + res[i].src + '">' +
                        '<p>' +
                        '<a class="layui-btn layui-btn-xs cftoggleUpload" style="float: left" lay-data="{field: \'picture\',data:{dir:\'room/picture\', field:\'picture\', room_picture_upload_index: \''+index+'\'}}">修改</a>' +
                        '<a class="layui-btn layui-btn-xs layui-btn-danger" onclick="this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);" style="float: right">删除</a>' +
                        '</p>' +
                        '</div>'
                    );
                }
            }
        });
        $(document).on('click', '.cftoggleUpload', function () {
            $('.toggleUpload').attr('lay-data', $(this).attr('lay-data'));
            $('.toggleUpload').trigger('click');
        });

        $('.replaceUploadImg').selectImages({
            confirm:function(res,elem,data) {
                let replaceUploadObj = $('#'+data.data.room_picture_upload_index);
                replaceUploadObj.find('img').attr('src', res[0].src);
                replaceUploadObj.find('img').attr('alt', res[0].src);
                replaceUploadObj.find('input').val(res[0].src);
            }
        });
        laydate.render({
            elem: '.day-time'
        });
        form.on('submit(setting)', function (data) {
            var field = data.field;
            var loadAdd = layer.msg('提交中', {icon: 16, time: 0, shade: 0.1, offset: '15px'});
            $.post("{:url('propertyWorkExpendApplyEdit')}", field, function (res) {
                layer.close(loadAdd);
                if (res.code === 0) {
                    window.location.reload();
                    layer.msg(res.msg, {icon: 6, offset: '15px'});
                } else {
                    layer.msg(res.msg, {icon: 5, offset: '15px'});
                }
            });
            return false;
        });
    });
</script>
{/block}